﻿using B.S.Data.MES.API.Applications.Management.SteamApplication.Command.RoleCommand;
using B.S.Domain.Accounts;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;

namespace B.S.Data.MES.API.Applications.Management.SteamApplication.CommandHandler.RoleCommandHandler
{
    public class RoleUpdateCommandHandler : IRequestHandler<RoleUpdateCommand, APIRequst<int>>
    {
        public RoleUpdateCommandHandler(IBaseRepository<RoleEntty> roleRepository)
        {
            RoleRepository = roleRepository;
        }

        public IBaseRepository<RoleEntty> RoleRepository { get; }

        public async Task<APIRequst<int>> Handle(RoleUpdateCommand request, CancellationToken cancellationToken)
        {
            request.Data.UpdateTime = DateTime.Now;
            var path = await RoleRepository.Update(request.Data);
            return new APIRequst<int>
            {
                Code = RequstCode.成功,
                Msg = "更新角色成功",
                Data = path
            };
        }
    }
}
